//
//  LLMenuItemData.m
//  lrlzapp
//
//  Created by dl on 16/2/25.
//  Copyright © 2016年 lrlz. All rights reserved.
//

#import "LLMenuItemData.h"

@implementation LLMenuItemData

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    return @{
            @"name" : @"name",
            @"jumpType" : @"jumpType",
            @"jumpTarget" : @"jumpTarget",
            @"imgUrl" : @"imgUrl",
            @"desc" : @"description"
    };
}

@end


@implementation LLMenuItemDataBag

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    return [super.JSONKeyPathsByPropertyKey mtl_dictionaryByAddingEntriesFromDictionary:
            @{
                    @"size" : @"size",
                    @"menuItem" : @"channel",
                    @"menuItemDatas" : @"list"
            }];
}

+ (NSValueTransformer *)menuItemJSONTransformer {
    return [MTLValueTransformer transformerUsingForwardBlock:^id(NSDictionary *json, BOOL *success, NSError *__autoreleasing *error) {
        NSError *localError = nil;
        LLMenuItem *item = [MTLJSONAdapter modelOfClass:LLMenuItem.class fromJSONDictionary:json error:&localError];
        if (localError) {
            JSONToModelError(LLMenuItem.class, error, json);
            return nil;
        }
        return item;
    }                                           reverseBlock:^id(LLMenuItem *model, BOOL *success, NSError *__autoreleasing *error) {
        NSError *localError = nil;
        NSDictionary *jsonDic = [MTLJSONAdapter JSONDictionaryFromModel:model error:&localError];
        if (localError) {
            ModelToJsonError(LLMenuItem.class, error, model);
            return nil;
        }
        return jsonDic;
    }];
}

+ (NSValueTransformer *)menuItemDatasJSONTransformer {
    return [MTLValueTransformer transformerUsingForwardBlock:^id(NSArray *jsonArray, BOOL *success, NSError *__autoreleasing *error) {
        NSError *localError = nil;
        NSArray *menuItems = [MTLJSONAdapter modelsOfClass:LLMenuItemData.class fromJSONArray:jsonArray error:&localError];
        if (localError) {
            JSONArrayToModelArrayError(LLMenuItem.class, error, jsonArray);
            return nil;
        }
        return menuItems;
    }                                           reverseBlock:^id(NSArray *models, BOOL *success, NSError *__autoreleasing *error) {
        NSError *localError = nil;
        NSArray *jsonArray = [MTLJSONAdapter JSONArrayFromModels:models error:&localError];
        if (localError) {
            ModelArrayToJsonArrayError(LLMenuItemData.class, error, models);
            return nil;
        }

        return jsonArray;
    }];
}

@end